<?php
namespace app\farm\model;

use app\BaseModel;
use think\facade\Db;

class WelfareColumn extends BaseModel
{
    //定义表名
    protected $name = 'lbfarm_v2_welfare_column';



    protected $append = [

        'create_time_text',

        'hours',

        'day'
    ];


    /**
     * @param $value
     * @param $data
     * @功能说明:
     * @author chenniang
     * @DataTime: 2022-08-23 17:05
     */
    public function getDayAttr($value,$data){

        if(!empty($data['create_time'])){

            return infoFriendTime($data['create_time']);

        }

    }

    /**
     * @param $value
     * @param $data
     * @功能说明:获取时间
     * @author chenniang
     * @DataTime: 2022-08-23 16:36
     */
    public function getHoursAttr($value,$data){

        if(!empty($data['create_time'])){

            return date('H:i:s',$data['create_time']);

        }

    }


    /**
     * @param $value
     * @param $data
     * @功能说明:
     * @author chenniang
     * @DataTime: 2022-07-25 11:37
     */
    public function getCreateTimeTextAttr($value,$data){

        if(!empty($data['create_time'])){

            return date('Y-m-d H:i',$data['create_time']);

        }

    }

    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:04
     * @功能说明:添加
     */
    public function dataAdd($data){

        $data['create_time'] = time();

        $res = $this->insert($data);

        return $res;

    }



    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:05
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $res = $this->where($dis)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:06
     * @功能说明:列表
     */
    public function dataList($dis,$page=10,$field='*'){

        $data = $this->where($dis)->field($field)->order('top desc,id desc')->paginate($page)->toArray();

        return $data;

    }


    /**
     * @author chenniang
     * @DataTime: 2020-09-29 11:43
     * @功能说明:
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }







}